﻿using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace BingDesktopChanger.Forms
{
    public partial class frmBrowse : Form
    {
        public frmBrowse()
        {
            InitializeComponent();
        }

        private ImageManager manager;

        private void frmBrowse_Load(object sender, EventArgs e)
        {
            this.manager = new ImageManager();
            var list = this.manager.GetFileList();
            foreach (string item in list)
            {
                string imageKey = Path.GetFileName(item);
                this.imgContainer.Images.Add(imageKey, Image.FromFile(item));
                var listItem = new ListViewItem(string.Empty, imageKey);
                listItem.Tag = item;
                listItem.ToolTipText = "Doble click para setear como fondo de pantalla";
                this.ltvList.Items.Add(listItem);
            }
        }

        private void ltvList_DoubleClick(object sender, EventArgs e)
        {
            if (this.ltvList.SelectedItems.Count > 0)
                WallPaperChanger.Set(new Uri(this.ltvList.SelectedItems[0].Tag.ToString()), WallPaperChanger.Style.Stretched);
            this.Close();
        }
    }
}
